﻿@using NetMongo.Entity
@{
    ViewBag.Title = "Asp.Net 使用MongoDB";
    int rowno = 0;
}
@model List<User>
<h3>Asp.Net 操作MongoDB</h3>
<div class="row">
    <div class="row">
        <input type="text" class="form-control m-r-sm pull-left" name="search" id="txtUserName" placeholder="姓名" />
        <button class="btn btn-sm btn-primary m-l-sm pull-left" id="btnQuery">查询</button>
        <a href="@Url.Action("UserAdd","Home")" class="btn btn-sm btn-primary pull-right">新增</a>
    </div>
    <div class="row">
       <hr />
    </div>
    <div class="row">        
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>兴趣爱好</th>
                    <th>备注</th>
                    <th>创建时间</th>
                    <th width="200">操作</th>
                </tr>
            </thead>
            <tbody>
                @if (Model != null)
            {
                foreach (var item in Model)
                {
                    rowno++;
                        <tr class="@(rowno % 2 == 0 ? "footable-odd" : "footable-even")" style="display: table-row;">
                            <td class="footable-visible">@rowno</td>
                            <td class="footable-visible">@item.UserName</td>
                            <td class="footable-visible">@item.Sex</td>
                            <td class="footable-visible">@item.Age</td>
                            <td class="footable-visible">@item.Interest</td>
                            <td class="footable-visible">@item.Remark</td>
                            <td class="footable-visible">@item.CreateTime</td>
                            <td align="center">
                                <a class="btn btn-info btn-sm" href="@Url.Action("UserEdit","Home",new { id = item.Id })"><i class="fa fa-edit">  编辑</i></a>
                                <a class="btn btn-danger btn-sm" href="javascript:void(0);" onclick="UserDelete('@item.Id');"><i class="fa fa-trash">  删除</i></a>
                            </td>
                        </tr>
                    }
                }
            </tbody>
        </table>
    </div>
</div>

@section Scripts {
    <script>
        //删除
        function UserDelete(id)
        {
            $.post("@Url.Action("UserDelete", "Home")", { id: id }, function (res) {
                if (res.success) {
                    alert("删除成功");
                    window.location.reload();
                }
                else {
                    alert(res.msg);
                }
            });
        }
        $(function () {
            //查询
            $("#btnQuery").click(function () {
                var search = $("#txtUserName").val();
                window.location.href = "@Url.Action("Index","Home")?search=" + search;
            });
        });
    </script>
}
